<?php
header('Content-type: text/xml');
require_once('session.php');
require_once('functions.php');

// Guess face shape
if($_SERVER['REQUEST_METHOD'] == "GET") {
	if (isset($_GET['shape']) && isset($_SESSION['current_face'])) {
		vote_face_shape($_SESSION['current_face'], $_GET['shape']);

		// Compare vote to majority of votes and recalculate the score
		update_score();

		$_SESSION['current_face'] = rand(1, 126);
		
		echo 
			"<xml>
			    <new_score>".$_SESSION['score']."</new_score>
			    <new_face>".$_SESSION['current_face']."</new_face>
			</xml>"; 
	}
}
?>